<template>
  <div class="todo-footer">
    <label>
      <input type="checkbox" v-model="selected" :disabled='isDisabled'/>
    </label>
    <span>已完成{{ sum }}</span> / <span> 全部{{ todoList.length }}</span>
    <button class="btn btn-danger" @click="AllDeleteHandle">清除已完成任务</button>
  </div>
</template>

<script>
/* eslint-disable */
export default {
  name: "Footer",
  props: ["todoList", "alreadyTodoHandle",'deleteAllplayedTodo'],
  data(){
    return {
      isDisabled:false
    }
  },
  computed: {
    selected: {
      get() {
        // 当每个item的都为选中状态的时候 已完成为选中状态
        // every方法用来判断是否每个都符合条件 返回值为布尔值 全部满足条件就返回true 有一个不符合条件就返回false
        return this.todoList.every((item) => item.done === true ) && this.todoList.length != 0;
      },
      set(value){
        this.alreadyTodoHandle(value)
      }
    },
    sum() {
      return this.todoList.reduce((prev, item) => {
        return item.done? prev+1 : prev;
      }, 0);
    },
  },
  updated(){
       if(this.todoList.length === 0){
          this.isDisabled = true
        }else{
          this.isDisabled=false
        }
  },
  methods:{
    AllDeleteHandle(){
     this.deleteAllplayedTodo()
    }
  }
};
</script>

<style scoped>
/*footer*/
.todo-footer {
  height: 40px;
  line-height: 40px;
  padding-left: 6px;
  margin-top: 5px;
}

.todo-footer label {
  display: inline-block;
  margin-right: 20px;
  cursor: pointer;
}

.todo-footer label input {
  position: relative;
  top: -1px;
  vertical-align: middle;
  margin-right: 5px;
}

.todo-footer button {
  float: right;
  margin-top: 5px;
}
</style>